<?php


namespace seecms\wechat\provider;

use magein\utils\Result;

class UserLogin extends \seecms\lib\provider\UserLogin
{
    const TYPE_SCAN_WX = 4;

    /**
     * @return string[]
     */
    public function support(): array
    {
        $data = parent::support();
        $data[self::TYPE_SCAN_WX] = __('login.method_wx_oauth');
        return $data;
    }

    public function doLogin($data): Result
    {
        extract($data);

        if ($type == self::TYPE_PHONE_CODE) {
            // 手机号码+验证码登录
            $result = $this->phone($phone, $code);
        } elseif ($type == self::TYPE_SCAN_WX) {
            // 微信扫码登录
            $result = $this->wx($data);
        } elseif ($type == self::TYPE_SCAN_APP) {
            // app扫码登录
            $result = $this->scan($user_id, $token);
        } else {
            // 账号密码登录
            $result = $this->username($username, $password);
        }

        return $result;
    }
}